<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ page import="org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter" %>
<%@ page import="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" %>
<%@ page import="org.springframework.security.web.WebAttributes" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="context.title"/></title>
	<%@ include file="/common/meta.jsp" %>
	<link href="${ctx}/css/yui.css" type="text/css" rel="stylesheet"/>
	<link href="${ctx}/css/style.css" type="text/css" rel="stylesheet"/>
	<script src="${ctx}/js/jquery.js" type="text/javascript"></script>
	<script src="${ctx}/js/validate/jquery.validate.js" type="text/javascript"></script>
	<script src="${ctx}/js/validate/messages_cn.js" type="text/javascript"></script>
	<script>

		var _check = setInterval("t()",500);//每隔0.5秒检查一次
		
		var ifreamid = "frame1";
		var frameTopName = "topFrame";
		var _check1;
		var ifr=document.createElement("iframe2");//以下创建一个隐藏的iframe   
		ifr.setAttribute("width",1024);   
		ifr.setAttribute("height",1024);   
		document.body.appendChild(ifr);   
		ifr.src=encodeURI("point-login-subfream.action");   
				
		function t(){
	        if(chxval("first") == "ok"){
		        $("#msg").text("正在登陆..");
		        //页面初始化成功
		        //提交表单
		        setSubmitForm();
		        //监听子系统页面是否加载成功
		        _check1 = setInterval("t1()",500);
		        clearInterval(_check);//加载完成后，清除定时器
	        }
		}

		//检测子系统主页面是否加载成功
		function t1(){
			var s;
			try{
			s = $(frameDocm(getIframeControl(ifreamid))).find("#scond").val();
		    if (s == "ok"){
			    $("#msg").text("登陆成功！正在跳转...");
		    	top.location.href($("#surl").val());
		    //	clearInterval(_check1);//加载完成后，清除定时器
		    }
			}catch(e){
			}
		}

		//获取ifream的上下文
		function getIframeControl(iframeId){
		    var ofrm = document.getElementById(iframeId).document;    
		    if (ofrm==undefined)
		    {
		        ofrm = document.getElementById(iframeId).contentWindow.document;
		        return ofrm;
		    }
		    else
		    {
		        var ie = document.frames[iframeId].document;
		        return ie;
		    } 
		}
		//设置ifream里的表单值
		function setSubmitForm(){
			 
			var url = $("#url").val();
			var username = $("#username").val();
			var pwd = $("#pwd").val();
			
			var formDom = $(getIframeControl(ifreamid)).find("#loginForm");
			var userDom = $(getIframeControl(ifreamid)).find("#j_username");
			var pwdDom = $(getIframeControl(ifreamid)).find("#j_password");
			//设置表单变量
			userDom.attr("name",username);
			pwdDom.attr("name",pwd);
			formDom.attr("action",url);
			//获取值
			$.post("point-login!namePasswd.action",null,function(data){
				if($(data).length != 1){
					window.location.href="login.action";
					return false;
				}
				var name = data.name;
				var passwd = data.passwd;
				if(name != "" && passwd != ""){
					userDom.val(name);
					pwdDom.val(passwd);
					formDom.trigger("submit");
				}
				},"json");
		}

		function chxval(ids){
			return $(getIframeControl(ifreamid)).find("#" + ids).val();
		}

		//获取子系统中的某一个document
		function frameDocm(docm){
			var ofrm = docm.getElementById(frameTopName).document;
		    if (ofrm==undefined)
		    {
		        ofrm = docm.getElementById(frameTopName).contentWindow.document;
		        return ofrm;
		    }
		    else
		    {
		        var ie = docm.frames[frameTopName].document;
		        return ie;
		    } 
		}
	</script>
</head>
<body>
<input type="hidden" value="${entity.url }"  id="url"/>
<input type="hidden" value='${entity.username }' id="username"/>
<input type="hidden" value='${entity.password }' id="pwd"/>
<input type="hidden" value="${subPointEntiry.url}" id="surl"/>
<center><div id="msg" align="center" style="text-align: center;"></div></center>
<iframe name="frame1" id="frame1" style="display: block" src="point-login-subfream.action" frameborder="0" height="1024" width="100%"></iframe>
</body>
</html>

